package com.hmall.common.config;

import com.hmall.common.interceptors.UserInfoInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//由于gateway网关使用的框架不是springMVC框架，gateway模块也引入了common模块，两个不同的框架会冲突，所以要让该配置类在网关中不生效
@Configuration
@ConditionalOnClass(DispatcherServlet.class)//只有当类路径中存在 DispatcherServlet（springMVC框架拥有的）时，
// 才会创建 MvcConfig 的 Bean 确保不会和gateway冲突

//添加springMVC拦截器
public class MvcConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new UserInfoInterceptor());
    }

}
